package com.ruoyi.threeViolation.service.impl;

import java.util.List;
import java.util.stream.Collectors;

import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.system.domain.SysDictItem;
import com.ruoyi.system.mapper.SysDictItemMapper;
import com.ruoyi.threeViolation.dto.SysUserDto;
import com.ruoyi.threeViolation.vo.SysUserVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.threeViolation.mapper.SysUserMapper;
import com.ruoyi.threeViolation.domain.SysUser;
import com.ruoyi.threeViolation.service.ISysUserService;

/**
 * 用户Service业务层处理
 *
 * @author lth
 * @date 2023-12-19
 */
@Service
public class SysUserServiceImpl implements ISysUserService
{
    @Autowired
    private SysUserMapper sysUserMapper;

    @Autowired
    private SysDictItemMapper sysDictItemMapper;

    /**
     * 查询用户
     *
     * @param id 用户主键
     * @return 用户
     */
    @Override
    public SysUser selectSysUserById(String id)
    {
        return sysUserMapper.selectSysUserById(id);
    }

    /**
     * 查询用户列表
     *
     * @param sysUser 用户
     * @return 用户
     */
    @Override
    public List<SysUser> selectSysUserList(SysUser sysUser)
    {
        return sysUserMapper.selectSysUserList(sysUser);
    }

    /**
     * 新增用户
     *
     * @param sysUser 用户
     * @return 结果
     */
    @Override
    public int insertSysUser(SysUser sysUser)
    {
        sysUser.setCreateTime(DateUtils.getNowDate());
        return sysUserMapper.insertSysUser(sysUser);
    }

    /**
     * 修改用户
     *
     * @param sysUser 用户
     * @return 结果
     */
    @Override
    public int updateSysUser(SysUser sysUser)
    {
        sysUser.setUpdateTime(DateUtils.getNowDate());
        return sysUserMapper.updateSysUser(sysUser);
    }

    /**
     * 批量删除用户
     *
     * @param ids 需要删除的用户主键
     * @return 结果
     */
    @Override
    public int deleteSysUserByIds(String[] ids)
    {
        return sysUserMapper.deleteSysUserByIds(ids);
    }

    /**
     * 删除用户信息
     *
     * @param id 用户主键
     * @return 结果
     */
    @Override
    public int deleteSysUserById(String id)
    {
        return sysUserMapper.deleteSysUserById(id);
    }

    /**     选择用户
    * @Author lth
    * @Description //TODO
    * @Date 19:37 2023/12/19
    * @Param
    * @return
     **/
    @Override
    public List<SysUserDto> selectUser(SysUserVo vo) {
        String realname = vo.getRealname();
        List<SysUserDto> dtoList = sysUserMapper.selectUser(realname);
        List<SysUserDto> sysUserDtoList = dtoList.stream().map(dto -> {
            //查询性别
            Integer sexValue = dto.getSex();
            SysDictItem sexText = sysDictItemMapper.getSex(sexValue);
            dto.setSex_dictText(sexText.getItemText());
            //状态
            Integer statusValue = dto.getStatus();
            SysDictItem status = sysDictItemMapper.getStatus(statusValue);
            dto.setStatus_dictText(status.getItemText());

            dto.setDeptTypes(null);
            dto.setOrgCodeText(null);
            return dto;
        }).collect(Collectors.toList());
        return sysUserDtoList;
    }

    @Override
    public SysUser getById(SysUser sysUser) {
        String id = sysUser.getId();
        SysUser user = sysUserMapper.getById(id);
        return user;
    }

}
